/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pb138.xml.wrda_data_layer;

import cz.muni.fi.pb138.xml.wrda.dao.WARDaoImpl;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.basex.core.BaseXException;
import org.basex.core.Context;
import org.basex.core.cmd.CreateDB;
import org.basex.core.cmd.DropDB;

/**
 *
 * @author Ondřej Chrastina 430596@mail.muni.cz
 */
public class DBInit {

    public static void main(String[] args) {
        Properties p = new Properties();
        try {
            p.load(WARDaoImpl.class.getResourceAsStream("/config.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            //WAR db recreation
            Context con = new Context();
            new DropDB(p.getProperty("db.war.name"));
            new CreateDB(p.getProperty("db.war.name"), "../WRDA_data_layer/src/main/resources/wardb.xml").execute(con);
            con.close();
        } catch (BaseXException ex) {
            Logger.getLogger(DBInit.class.getName()).log(Level.SEVERE, "Cannot create war database", ex);
        }

        try {
            //XSD db recreation
            Context con = new Context();
            new DropDB(p.getProperty("db.xsd.name"));
            new CreateDB(p.getProperty("db.xsd.name"), "../WRDA_data_layer/src/main/resources/xsdTemplate.xml").execute(con);
            con.close();
        } catch (BaseXException ex) {
            Logger.getLogger(DBInit.class.getName()).log(Level.SEVERE, "Cannot create xsd database", ex);
        }

        try {
            //WSDL db recreation
            Context con = new Context();
            new DropDB(p.getProperty("db.wsdl.name"));
            new CreateDB(p.getProperty("db.wsdl.name"), "../WRDA_data_layer/src/main/resources/wsdl.xml").execute(con);
            con.close();
        } catch (BaseXException ex) {
            Logger.getLogger(DBInit.class.getName()).log(Level.SEVERE, "Cannot create wsdl database", ex);
        }

        
        
        
        

    }
}
